<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= htmlWebpackPlugin.options.title %></title>
    <style>
       .upload{
            height: 100px;
            line-height: 100px;
            text-align: center;
            width: 100px;
            border: 1px solid #ddd;
            position: relative;
        }
        .plus{
            font-size:28px;
        }
        input{
            top:0;
            left:0;
            position: absolute;
            width: 100px;
            height: 100px;
            opacity: 0;
        }
    </style>
  </head>
  <body>
    <div class="upload">
      <span class="plus">+</span>
      <input type="file" id="input" accept=".jpg, .jpeg, .png">
    </div>
    <img src="" alt="" id="img">
    <!-- built files will be auto injected -->
  </body>
</html>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
  document.getElementById("input").addEventListener("change",function(e){
    Array.from(e.target.files).map((f=>{
      //构造from表单格式数据
      let formDate=new FormData();
      formDate.append("file",f);
      axios.post("http://linweiqin.cn:8001/v1/addimg/avatar",formDate).then(res=>{
        //拼接图片在线地址
        let imageUrl="http://linweiqin.cn:8001/img/"+res.data.image_path;
        document.getElementById("img").setAttribute("src",imageUrl)
      })
    }))
  })
</script>
